using System;
using System.Reflection;
using System.Drawing;
using System.Drawing.Imaging;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Windows.Forms;

namespace stsdev {

  class FeatureWithApplicationPageSolutionProvider : ISolutionProvider {

    public string Title {
      get { return "Application Pages with Navigation Feature (C# assembly)"; }
    }

    //Added 2/10/08 DMANN
    public bool LaunchSolutionOnComplete
    {
        get { return false; }
    }


    public void InitializeSolution() {
      SolutionBuilder.AssemblyDeployment = true;
      SolutionBuilder.SafeControlSettings = false;
      SolutionBuilder.DeploymentTarget = AssemblyDeploymentTarget.GlobalAssemblyCache;
      SolutionBuilder.CasPermissions = false;
    }

    string[] AppPageNames = { "AppPage1", "AppPage2", "AppPage3" };

    public void AddSolutionItems() {

      ImageFileBuilder.Create(Properties.Resources.Binoculars32, "Binoculars32.gif");
      foreach (string AppPageName in AppPageNames) {
        ApplicationPageBuilder.Create(AppPageName);
      }
      FeatureBuilder.CreateElementManifest("ApplicationPageNavigation.xml", ElementWriter);
      FeatureBuilder.Create(SolutionBuilder.SolutionName,
                            FeatureScopeEnum.Site);
    }

    private void ElementWriter(XmlWriter writer) {

      int SequenceNumber = 1001;

      foreach (string AppPageName in AppPageNames) {
        writer.WriteStartElement("CustomAction");
        writer.WriteAttributeString("Id", AppPageName + "NavigationMenu");
        writer.WriteAttributeString("GroupId", "SiteActions");
        writer.WriteAttributeString("Location", "Microsoft.SharePoint.StandardMenu");
        writer.WriteAttributeString("Sequence", SequenceNumber.ToString());
        writer.WriteAttributeString("Title", AppPageName);
        writer.WriteAttributeString("Description", "Navigate to " + AppPageName);
        writer.WriteStartElement("UrlAction");
        string AppPageUrl = "~sitecollection/_layouts/" + SolutionBuilder.SolutionName + @"/" + AppPageName +  ".aspx";
        writer.WriteAttributeString("Url", AppPageUrl);
        writer.WriteEndElement(); // </UrlAction>
        writer.WriteEndElement(); // </CustomAction>  
        SequenceNumber++;
      }      
    }  
  
  }
}
